package com.cqtczh.qhd.interceptor;


import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


@Component("default")
public class DefaultInterceptor extends HandlerInterceptorAdapter{
	@Override  
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception{  
		return true;
	}  
      
    @SuppressWarnings("unchecked")
	@Override  
    public void postHandle(HttpServletRequest request,HttpServletResponse response,Object handler,ModelAndView modelAndView) throws Exception{  
    	if(modelAndView==null){
    		return;
    	}
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
		modelAndView.addObject("path",basePath);
		Map<String,Object> map = new HashMap<String, Object>();
		Enumeration<String> em = request.getSession().getAttributeNames();
		while(em.hasMoreElements()){
			String key = em.nextElement();
			map.put(key, request.getSession().getAttribute(key));
		}
		modelAndView.addObject("session",map);
    }  
      
    @Override  
    public void afterCompletion(HttpServletRequest request,HttpServletResponse response,Object handler,Exception ex) throws Exception{  
    }  
}
